home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-08 | 8.7 KB | 345 lines | [TEXT/MSET] |
- \ Neon compatibility
- \ This file is aimed at helping the transition from Neon to Mops.
-
- false -> Neon?
-
- need dialog
- need alertq
-
- \ Only include those lines when you use dialogs or alert" respectively.
-
- true -> Neon?
-
- \ ( b -- bool ) make a Forth boolean into a Toolbox boolean
- \ neither mops nor neon sensitive
- : Bool if $ 100 else 0 then makeInt ;
-
- \ Words involving the loop counter i. We don't need these in Mops
- \ since e.g. i @ compiles exactly the same code as i@ would, due
- \ to our optimization.
-
- : I@ postpone i postpone @ ; immediate
- : IW@ postpone i postpone w@ ; immediate
- : IC@ postpone i postpone c@ ; immediate
-
- : I! postpone i postpone ! ; immediate
- : IW! postpone i postpone w! ; immediate
- : IC! postpone i postpone c! ; immediate
-
- : 8+ 8 + ;
- : 2OVER 3 pick 3 pick ;
- : 2SWAP { n1 n2 n3 n4 -- n3 n4 n1 n2 } n3 n4 n1 n2 ;
- : -DUP ?dup ;
- : PICK hide 1- pick ;
-
- : 2@ dup @ swap 4 + @ ;
- : 2! swap over 4 + ! dup drop ! ;
-
-
- : <SUPER postpone super( ; immediate
- : <INDEXED indexed ;
-
- : COMPILE postpone postpone ; immediate
- : [COMPILE] postpone postpone ; immediate \ Believe it or not!
-
- : 'C state
- IF
- postpone [']
- ELSE
- '
- THEN ; immediate
-
- : ' postpone 'c ; immediate
-
- : CFA ;
- : PFA >body ;
-
- : CREATE colHdr ;
-
- : PUSHD0 $ 2D00 w, ; immediate \ move.l d0,-(a6)
- : PUSHA0 $ 2D08 w, ; immediate \ move.l a0,-(a6)
- : POPD0 $ 201E w, ; immediate \ move.l (a6)+,d0
- : POPA0 $ 205E w, ; immediate \ move.l (a6)+,a0
-
- : NEXT, $ 4E75 w, ; \ RTS
-
- : <[ postpone [ ; immediate
- : ]> postpone ] ; immediate
-
-
- handle TempH
- ptr TempP
-
- : getHSize \ ( hdl -- size )
- put: tempH size: tempH ;
-
- : setHSize \ ( hdl size -- )
- swap put: tempH setSize: tempH ;
-
- : NEWHANDLE \ ( size -- hdl )
- new: tempH get: tempH ;
-
- : NEWPTR \ ( size -- ptr )
- new: tempP get: tempP ;
-
- : KILLHANDLE
- put: tempH release: tempH ;
-
- : DISPOSE
- put: tempP release: tempP ;
-
-
- \ This stuff allows Neon pointer type objects in Mops to allow a programmer
- \ to choose whether to use handle type objects after the conversion to
- \ Mops is complete.
-
- handle newObjVar \ temporary handle to create new obj a la Mops
-
- : >heap { ^class \ objHdl objLen -- ^obj }
-
- \ pinched from NEWOBJ:, but save obj length for erase
- ^class cl>len 8 + dup -> objLen new: newObjVar
-
- moveHi: newObjVar \ debatable
- get: newObjVar -> objHdl \ save handle
-
- ptr: newObjVar objLen erase \ clear it like Neon
-
- \ let mops do its thing
- ^class obj: newObjVar make_obj
-
- \ do not unlock, cannot use newObjVar
- \ as classinit: may cause >heap to be re-entered
- objHdl @ ( stripAddr ) 8 +
- ;
-
- : >dispose ( ^obj -- )
- 8 - popA0 call RecoverHandle pushA0
- ?dup if killHandle then
- ;
-
-
- : +BASE ;
- : -BASE ;
-
- : (ABS) ^base ;
-
- \ Conditionals
-
- : LAND 0<> swap 0<> and negate ;
- : LOR 0<> swap 0<> or negate ;
- : LXOR 0<> swap 0<> xor negate ;
-
- : = hide postpone = postpone negate ; immediate
- : <> hide postpone <> postpone negate ; immediate
- : < hide postpone < postpone negate ; immediate
- : <= hide postpone <= postpone negate ; immediate
- : > hide postpone > postpone negate ; immediate
- : >= hide postpone >= postpone negate ; immediate
- : 0= hide postpone 0= postpone negate ; immediate
- : 0> hide postpone 0> postpone negate ; immediate
- : 0>= hide postpone 0>= postpone negate ; immediate
- : 0< hide postpone 0< postpone negate ; immediate
- : 0<= hide postpone 0<= postpone negate ; immediate
- : 0<> hide postpone 0<> postpone negate ; immediate
-
- : NOT 0= ;
-
- : f= hide postpone f= postpone negate ; immediate
- : f<> hide postpone f<> postpone negate ; immediate
- : f< hide postpone f< postpone negate ; immediate
- : f<= hide postpone f<= postpone negate ; immediate
- : f> hide postpone f> postpone negate ; immediate
- : f>= hide postpone f>= postpone negate ; immediate
-
- : f0= hide postpone f0= postpone negate ; immediate
- : f0> hide postpone f0> postpone negate ; immediate
- : f0< hide postpone f0< postpone negate ; immediate
-
- : * *L ;
-
- : D= rot = rot rot = and ;
-
-
- : CLASSERR" postpone ?error ; immediate
-
- : ?isObj obj? ;
-
- : >UC upper ;
-
- : SYSPAT hide sysPat get: [ ] ;
-
-
- :class VAR hide <super var
-
- \ ( -- ^obj ) get contents as an object pointer
- :M OBJ: ^base @ dup 0= classErr" 157 ;M \ invalid obj addr
- :M DISPOSE: ^base @ >dispose clear: self ;M \ dispose of heap ptr
- :M EXEC: ^base @ dup 0= classErr" 131 execute ;M
- :M =: ^base @ swap ! ;M \ r to l assignment to address
- ;class
-
- :class MENU hide <super menu
-
- \ ( resID -- ) store menuID
- :M INIT: put: resID ;M
-
- \ ( cfa0...cfaN resid -- ) put resid and handlers in menu
- :M PUT: Put: ResId limit: self Put: Super ;M
-
- \ ( item# -- addr len ) get string for item #
- :M GET: { item -- addr len } get: mhndl item 1+ makeInt
- buf255 +base call GetItem buf255 count ;M
-
- \ ( item# -- )
- :M delete: Get: Mhndl swap makeInt call delMenuItem ;M
-
- \ ( item# addr len -- )
- :M SET: putitem: super ;M
-
- \ ( item# -- ) Enable a menu item
- :M ENABLE: Get: Mhndl swap makeInt call EnableItem ;M
-
- \ ( item# -- ) Grey and disable an item
- :M DISABLE: Get: Mhndl swap makeInt call DisableItem ;M
-
- ;class
-
- :class DIALOG hide <super dialog
-
- :m ACTIONS: limit actions: super ;M
- :m HANDLE: itemHandle: super ;m
- :m INIT: put: resID ;m
- :m GET: getitem: super ;m
- :m PUT: putitem: super ;m
- :m HILITE: setBold: super ;m
-
- ;class
-
- :class ARRAY hide <super array
-
- :m PUT: idxbase limit 4* bounds ?DO i ! 4 +LOOP ;M
- :m DISPOSE: \ ( item# -- )
- ^elem @ >dispose ;m
-
- ;class
-
- :CLASS x-Array hide <Super x-Array
- :M put: limit put: super ;M
- :M actions: limit actions: super ;M
- ;CLASS
-
- :CLASS window hide <Super window
- :M actions: 4 actions: super ;M
- :M zoom: ( code -- ) drop ;M
- ;CLASS
-
-
- \ String needs to be redefined with the Neon method names that are different
- \ from Mops.
-
-
- :CLASS BasicStr <Super Handle
-
- Var offset
-
- \ this method returns the handle - replaces get: in super
- :M HANDLE: get: super ;M
-
- \ interface method to the Toolbox Munger utility
- :M REPLACE: { addr1 len1 addr2 len2 -- offs } 0
- get: super get: offset dup 0< classErr" 151
- addr1 dup IF +base THEN len1 addr2 dup IF +base THEN len2
- trap$ a9e0 ( call Munger ) put: offset ;M
-
- \ allocate the string on the heap
- :M NEW: 0 new: super clear: offset ;M
-
- \ set the string to the null string
- :M CLEAR: 0 setSize: self clear: offset ;M
-
- \ ( offs -- ) set new offset for string
- :M MOVETO: size: self min put: offset ;M
-
- \ ( -- addr len ) return the entire string
- :M GET: ptr: self size: self ;M
-
- \ ( -- addr len ) map string to upper case and get it
- :M UC: get: self over +base over >uc ;M
-
- \ ( addr len -- ) replace entire string with replacement string
- :M PUT: { addr len -- } clear: offset
- 0 -1 addr len replace: self ;M
-
- :M INSERT: { addr len -- } addr 0 addr len replace: self ;M
-
- :M ADD: { addr len -- } 64000 moveto: self
- addr len insert: self ;M
-
- \ ( char -- ) append a char to end of string
- :M +: pad c! pad 1 add: self ;M
-
- \ ( -- chr t OR f) return char at offset and advance - false if at end
- :M NEXT: get: offset size: self <
- IF get: offset ptr: self + c@ true 1 +: offset
- ELSE false
- THEN ;M
-
- \ ( -- )
- :M PRINT: get: self type ;M
-
- ;CLASS
-
-
- \ String is a dynamic heap based string object that can grow and shrink
-
- :CLASS String <Super BasicStr
-
- \ ( -- offs ) return the current offset
- :M WHERE: get: offset ;M
-
- \ move to the 0th byte in the string
- :M START: 0 moveTo: self ;M
-
- \ assign this string to any object that accepts addr len
- :M =: { theObj -- } get: self put: theObj ;M
-
- \ ( chr len -- ) clear the string and set it to len bytes of chr
- :M FILL: buf255 swap put: self \ use put with arbitrary data
- get: self rot Fill ;M
-
- \ name an object using this string
- :M NAME=: { theObj -- } get: self name: theObj ;M
-
- \ ( len -- ) return the substring starting at offset
- :M SUBSTR: { len -- addr len } get: offset 0< classErr" 151
- ptr: self get: offset +
- size: self get: offset - len min 0 max ;M
-
- :M DELETE: { addr len -- } addr len addr 0 replace: self ;M
-
- :M INDEXOF: { addr len -- offs } addr len 0 0 replace: self
- get: offset dup 0<
- IF drop false
- ELSE true
- THEN ;M
-
- \ ( char -- offs t OR f ) find a single character in the string
- :M CHAROF: pad c! pad 1 indexof: self ;M
-
- \ ( ^fcb -- rc ) Fill string from file object
- :M READ: { theFcb len -- rc } len setsize: self
- get: self read: thefcb
- bytesRead: thefcb setSize: self ;M
-
- \ ( ^fcb -- rc ) Fill string from file object
- :M READLINE: { theFcb len -- rc } len setSize: self
- get: self readLine: thefcb
- bytesRead: thefcb setSize: self ;M
-
- \ ( rect just -- ) draw string justified in rect
- :M DRAW: { tRect just -- } ptr: self +base size: self
- tRect +base just makeInt trap$ a9ce ( call TextBox ) ;M
-
- ;CLASS
-